function aminvar = greedyargminVar(vbeta, Dstart, levels)
    
    global n Vstar
    
       %note: all arguments are full vectors for all observatiosn
       
       
        
       Dstar=Dstart;
       Vstar= vbeta(Dstar);
       contin =true;
       
       
       while contin
            contin= false;
            i=1;
            while i<=levels
                
                changes= combnk(1:n, i);
                for c=1:length(changes);
                    d= Dstar;
                    for j=1:i
                        d(changes(c,j))= 1- d(changes(c,j));
                    end
                    vnew = vbeta(d);
                    if vnew < Vstar
                        Dstar=d;
                        Vstar=vnew;
                        contin=true;
                        i=levels;
                        break;
                    end
                end
                i=i+1;
            end
       end
       
 
aminvar=Dstar;       


return
